package com.webchat.client.payment.controller;


import com.webchat.client.payment.service.ChatMessageService;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.helper.SessionHelper;
import com.webchat.domain.vo.response.chatting.ChattingListResponseVO;
import com.webchat.domain.vo.response.mess.ChatMessageResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/client-service/chat/message")
public class ChatMessageController {

    @Autowired
    private ChatMessageService chatMessageService;

    /**
     * 查询用户对话列表
     *
     * @param lastChatTime 采用瀑布流式翻页加载
     * @param size 对话列表展示最新对话数
     * @return
     */
    @GetMapping("/chatting/list")
    public APIResponseBean<List<ChattingListResponseVO>> listChatting(@RequestParam(name = "lastChatTime", required = false) Long lastChatTime,
                                                                      @RequestParam(name = "size", required = false, defaultValue = "100") Integer size) {
        String userId = SessionHelper.getCurrentUserId();
        return APIResponseBeanUtil.success(chatMessageService.listChatting(userId, lastChatTime, size));
    }

    /***
     * 查询跟用户聊天记录
     * @return
     */
    @GetMapping("/list/{chatUserId}")
    public APIResponseBean<List<ChatMessageResponseVO>> list(@PathVariable String chatUserId,
                                                             @RequestParam(value = "size", required = false, defaultValue = "50") Integer size,
                                                             @RequestParam(value = "lastId", required = false) Long lastId,
                                                             @RequestParam(value = "fixedMessageId", required = false) Long fixedMessageId) {
        String currUserId = SessionHelper.getCurrentUserId();
        return APIResponseBeanUtil.success(
                chatMessageService.list(currUserId, chatUserId, lastId, fixedMessageId, size));
    }

}
